define(function(require, exports, module) {
    var $ = require("$"),
        app = require("../application/app"),
        config = app.config,
        method = app.method;
    var baidu = require("./baidu.js");
    var google = require("./google.js");
    var tencent = require("./tencent.js");


    var iwork365map = function() {
        this.op = {
            lat: 31.256071,
            lng: 121.462096,
            adr: "上海火车站",
            type: "baidu"
        }
        this.maps = {};
        this.is_change = false;
        this.is_default = true;
    }
    iwork365map.prototype.init = function($warp) {
        var self = this;
        this.$warp = $warp;
        self.el = self.get_els();
        var keys = self.el.suggestId.val();
        if ($.trim(keys).length > 0) {
            self.op = {
                lat: self.el.lat.val(),
                lng: self.el.lng.val(),
                adr: keys,
            };
            self.is_default = false;
        }
        self.load_map();
        $(".js_map_search", $warp).click(function() {
            self.maps.search();
        });
        $(".js_map_type", $warp).on("click", function(e) {
            self.is_change = true;
            $("#l-map", $warp).css("background-color", "white").html("<div class='load pull-left'>地图加载中...</div>")
            self.load_map();
        })
    };
    iwork365map.prototype.load_map = function() {
        var self = this;
        switch (self.get_type()) {
            case "baidu":
                self.maps = new baidu();
                break;
            case "google":
                self.maps = new google();
                break;
            case "tencent":
                self.maps = new tencent();
                break;
            default:
                self.maps = new baidu();
                break;
        }
        self.maps.load();
    };
    iwork365map.prototype.get_els = function() {
        return {
            lat: $(".js_map_lng", this.$warp),
            lng: $(".js_map_lat", this.$warp),
            suggestId: $(".js_map_key", this.$warp)
        }
    };
    iwork365map.prototype.get_type = function() {
        return $(".js_map_type:checked", this.$warp).data("mapty");
    };

    return iwork365map;
});
